﻿using System.IO;
using System.Text;

namespace Builder
{
    public class HTMLBuilder : Builder
    {
        string fileName;
        TextWriter writer;

        public string GetResult()
        {
            return fileName;
        }

        public override void MakeTitle(string title)
        {
            fileName = title + ".html";

            writer = new StreamWriter(fileName, false, Encoding.Default);
            writer.WriteLine("<html><head><title>" + title + "</title></head><body>");
            writer.WriteLine("<h1>" + title + "</h1>");
        }

        public override void MakeString(string str)
        {
            writer.WriteLine("<p>" + str + "</p>");
        }

        public override void MakeItems(string[] items)
        {
            writer.WriteLine("<ul>");

            foreach (string item in items)
            {
                writer.WriteLine("<li>" + item + "</li>");
            }

            writer.WriteLine("</ul>");
        }

        public override void Close()
        {
            writer.WriteLine("</body></html>");
            writer.Close();
        }
    }
}
